package hackathon.techbooster.kuraudokakeibo;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailActivity extends Activity implements OnDismissListener{

	Dialog progressDialog = null;
	private DataTask dTask = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail);

        dTask = new DataTask();
    	dTask.execute();

    }

    public class DataTask extends AsyncTask<Void, Void, Void> {

		@Override
		protected void onPreExecute() {
			super.onPreExecute();

	        // プログレスダイアログ表示
	     	showDialog(0);
		}

		@Override
		protected Void doInBackground(Void... params) {
			// データ取得

			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);

			//画面表示
			Record record = new Record();
			record.loadRecord(getApplicationContext(), "record.txt");
	        TextView sdate = (TextView)findViewById(R.id.sdate);//日付
	        sdate.setText("6月9日");
	        ImageView iv = (ImageView)findViewById(R.id.receipt);//写真
	        iv.setImageResource(R.drawable.ic_launcher);
	        TextView bunrui = (TextView)findViewById(R.id.bunrui);//分類
	        bunrui.setText(record.getCategory());
	        TextView hinmoku = (TextView)findViewById(R.id.hinmoku);//品目
	        hinmoku.setText(record.getName());
	        TextView kingaku = (TextView)findViewById(R.id.kingaku);//金額
	        kingaku.setText(record.getValue() + "");

			//ダイアログ消去
			if(progressDialog != null && progressDialog.isShowing()){
				progressDialog.dismiss();
			}
		}
    }

	@Override
	protected Dialog onCreateDialog(int id) {

		progressDialog = new CustomProgressDialog(this);

		return progressDialog;
	}

	@Override
	public void onDismiss(DialogInterface dialog) {

		dialog.dismiss();

	}
}